export default {
  state: {
    home_title: '', //标题
    now_page: 'Home',
    home_footer_nav: [
      {
        name: "社区首页",
        checked: true,
        icon1: "icon_img icon_img_a1",
        icon2: "icon_img icon_img_a2",
        href: "/"
      },
      {
        name: "社区广场",
        checked: false,
        icon1: "icon_img icon_img_b1",
        icon2: "icon_img icon_img_b2",
        href: "/home/sqgc_list"
      },
      {
        name: "社区商城",
        checked: false,
        icon1: "icon_img icon_img_c1",
        icon2: "icon_img icon_img_c2",
        href: "/shop"
      },
      {
        name: "我的",
        checked: false,
        icon1: "icon_img icon_img_d1",
        icon2: "icon_img icon_img_d2",
        href: "/my"
      }
    ],
    home_footer_nav_index: 0,

    home_banner: '',//首页banner
    first_banner: '',//第一张
    last_banner: '',//第二章

    show_add_square: false,  //是否显示 发表广场说说 框

    show_upload_img_view: true, // 是否显示上传图片选择
    /*
      上传图片的类型 upload_img_type
    *     square-->社区广场 上传图片
    *     user-->用户头像 上传图片
    *     goods-->商品评论 上传图片
    *
    * */
    upload_img_type: 'square',
    upload_img_sign:'',
    upload_square_imgs: [],
    upload_user_imgs: "",
    upload_goods_imgs: [],


    show_edit_user_info_view:false


  },
    mutations: {
    home_state(state, name) {
      state.home_state_page = name;
    },
    open_edit_user_info_view(state,tf){
      state.show_edit_user_info_view = tf;
    },
    change_home_page(state, opt) {

      state.home_title = opt.title;
      state.now_page = opt.page_name;
      console.log(state.now_page)
    },
    change_home_nav(state, k) {

      if (k == 2) {
        //点击商城按钮 直接跳出
        return
      }
      state.home_footer_nav_index = k;
    },
    up_data_home_banner(state, list) {
      state.home_banner = list;
      state.first_banner = list[0].pic;
      state.last_banner = list[list.length - 1].pic;
    },

    open_add_square_view(state, tf) {
      state.show_add_square = tf;
    },

    open_upload_img_view(state, type) {
      // state.show_upload_img_view = tf;
      mui("#upload_img_component_sheet").popover(type);
    },
    change_upload_img_type(state, type) {
      state.upload_img_type = type;
    },

    save_upload_img_url(state, params) {

      let img_url = params.path;
      let sign = params.sign;
      if(state.upload_img_sign == sign){
        console.log("签名相同，跳出方法")
        return;
      }
      console.log("签名不同，继续执行")
      // 根据当前的上传类型，将图片存入不同的数组中
      // 如果参数为 reset 则将所有数据清空
      if (img_url == "reset") {
        state.upload_square_imgs = []
        state.upload_user_imgs = []
        state.upload_goods_imgs = []
        return
      }
      // 广场图片
      if (state.upload_img_type == 'square') {
        if (state.upload_square_imgs.length >= 3) {
          mui.toast("最多上传三张图片")
          return
        }
        console.log("广场图片，push")
        state.upload_square_imgs.push(img_url)

      }
      // 用户头像
      if (state.upload_img_type == 'user') {
        console.log("用户头像_push_img")
        console.log("用户头像："+img_url)
        state.upload_user_imgs = img_url
      }
      // 商品评论
      if (state.upload_img_type == 'goods') {
        if (state.upload_goods_imgs.length >= 3) {
          mui.toast("最多上传三张图片")
          return
        }
        console.log("商品评论_push_img")
        state.upload_goods_imgs.push(img_url)
      }
      console.log("将状态中的签名保存为当前的")

      state.upload_img_sign = sign;
    },
    del_upload_img(state,params){
      let sign = params.sign;
      if(state.upload_img_sign == sign){
        console.log("签名相同，跳出方法")
        return;
      }
      if(params.type=='square'){
        let k = parseInt(params.k);
        console.log("splice("+k+",1)")
        state.upload_square_imgs.splice(k,1)
        console.log(JSON.stringify(state.upload_square_imgs))
      }

      if(params.type=='goods'){

        let k = params.k;
        state.upload_goods_imgs.splice(k,1)
      }
      state.upload_img_sign = sign

    }

  },

}
